package com.example.springbootmybatis.service.impl;

import com.example.springbootmybatis.entity.ECharsData;
import com.example.springbootmybatis.mapper.ECharsMapper;
import com.example.springbootmybatis.service.ECharsDataService;
import com.example.springbootmybatis.util.ToolUtil;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.*;

/**
 * 作者： Administrator
 * 日期: 2024/1/12/012
 * Description :
 */
@Service
@Slf4j
public class ECharsDataServiceImpl implements ECharsDataService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ECharsMapper eCharsMapper;

    @Override
    public ECharsData getECharsData() throws ParseException {
        ECharsData eCharsData = new ECharsData();
        eCharsData.setVisitsCount(redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_visitor") == null ? 0 : (Integer) redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_visitor"));
        eCharsData.setBorrowCount(redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_Borrow") == null ? 0 : (Integer) redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_Borrow"));
        eCharsData.setLendCount(redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_lend") == null ? 0 : (Integer) redisTemplate.opsForValue().get(ToolUtil.DateFormat(new Date()) + "_lend"));
        return eCharsData;
    }


    @Override
    public void setBorrowMonth() {
        redisTemplate.opsForValue().set("BorrowMonth",eCharsMapper.getBorrowMonth());
    }

    @Override
    public void setReturnMonth() {
        redisTemplate.opsForValue().set("ReturnMonth",eCharsMapper.getReturnMonth());
    }

    @Override
    public List<Integer> getBorrowMonth() {
        return  (List<Integer>)redisTemplate.opsForValue().get("BorrowMonth");
    }

    @Override
    public List<Integer> getReturnMonth() {
        return  (List<Integer>)redisTemplate.opsForValue().get("ReturnMonth");
    }
}
